﻿#include "mainwindow.h"
#include "./ui_mainwindow.h"

#include "customgraphicsview.h"
#include "customrectitem.h"
#include <QGraphicsScene>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 1. 创建场景
    QGraphicsScene *scene = new QGraphicsScene(this);
    scene->setSceneRect(0, 0, 800, 600); // 设置场景大小

    // 2. 创建自定义视图
    CustomGraphicsView *view = new CustomGraphicsView(this);
    view->setScene(scene);

    // 3. 将视图设置为主窗口的中心部件
    setCentralWidget(view);

    // 4. 在场景中添加几个初始矩形
    CustomRectItem *rect1 = new CustomRectItem(QRectF(50, 50, 100, 100));
    scene->addItem(rect1);

    CustomRectItem *rect2 = new CustomRectItem(QRectF(200, 150, 120, 80));
    scene->addItem(rect2);
}

MainWindow::~MainWindow()
{
    delete ui;
}

